﻿@model System_User_Info
@{
    ViewBag.Title = "LoginUserInfoEdit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<style>
    .hide {
        display: none;
    }
</style>
<div>

    <div class="pad20">
        <form id="UserForm" method="post" class="form-horizontal margin10-t">
            @Html.HiddenFor(model => model.ID)
            <div class="contrl">
                <label for="User_Name">用户名称</label>
                @Html.TextBoxFor(o => o.User_Name, new { @class = "input" })
                @Html.HiddenFor(model => model.ID)
            </div>
            <div class="contrl">
                <label for="oldPassword">旧密码</label>
                @Html.Password("oldPassword", "", new { @class = "input" })
                <em id="errTips" class="hide">请输入旧密码</em>
            </div>
            <div class="contrl">
                <label for="Password">新密码</label>
                @Html.Password("Password", "", new { @class = "input" })
            </div>
            <div class="contrl">
                <label for="ConfirmPassword">确认新密码</label>
                @Html.Password("ConfirmPassword", "", new { @class = "input" })
            </div>
            <div class="contrl">
                <label for="Email">邮箱</label>

                @Html.TextBoxFor(o => o.Email, new { @class = "input" })
            </div>

            <div class="contrl">
                <label for="Mobile">手机</label>
                @Html.TextBoxFor(o => o.Mobile, new { @class = "input" })
            </div>
            <div class="contrl">
                <label>&nbsp;</label>
                <button type="button" class="btn btn-primary" onclick="save()">保存</button>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
    var t = true;
    function save() {
        if ($("input[name='Password']").val() != "") {
            if ($("input[name='oldPassword']").val() == "") {
                $("#errTips").addClass("error");
                $("#errTips").removeClass("hide");
                return false;
            }
        }
        var postData = $("#UserForm").formSerialize();
        var url = "@Url.Action("LoginUserInfoEdit", "System")";
        var options = {
            type: 'POST',
            data: postData,
            url: url,
            async: false,
            success: showResponse
        };
        if ($("#UserForm").validate().form()) {
            if (t) {
                t = false;
                $.ajax(options);
                t = true;
            }
        }
    }
    function showResponse(msg) {
        if (msg == 'y') {
            layer.msg('保存成功！', { icon: 1, time: 1000 }, function () {
                var url = "@Url.Action("HomeIndex", "Home")";
                window.parent.location.href = url;

            });
            @*$.success('保存成功！', '提示', function () {
                var url = "@Url.Action("HomeIndex", "Home")";
                window.parent.location.href = url;
            });*@

        } else if (msg == 'n') {
            layer.alert("保存失败,请重试", { icon: 5 });

        } else if (msg == 'w') {
            $("#errTips").html("请输入正确的旧密码");
            $("#errTips").addClass("error");
            $("#errTips").removeClass("hide");
        }
    }

    $(document).ready(function () {
        $("#oldPassword").focus(function () {
            $("#errTips").removeClass("error");
            $("#errTips").addClass("hide");
        });

        $("#UserForm").validate({
            rules: {
                User_Name: {
                    required: true,
                    minlength: 2,
                    maxlength: 50
                },
                Password: { required: true, minlength: 6, maxlength: 100 },
                ConfirmPassword: { equalTo: "#Password" },
                Mobile: { minlength: 11, maxlength: 11 },
                Email: { required: true, email: true }

            },
            messages: {
                User_Name: {
                    required: "请输入用户名称",
                    minlength: "长度不能少于2位",
                    maxlength: '长度不能大于50位'
                },
                Password: {
                    required: "请输入密码",
                    minlength: "长度不能少于6位",
                    maxlength: '长度不能大于100位'

                },
                ConfirmPassword: {
                    equalTo: "两次输入密码不一致"
                },
                Mobile: {
                    minlength: "请输入11位的手机号码",
                    maxlength: "请输入11位的手机号码"
                },
                Email: {
                    required: "邮箱不能为空",
                    email: "邮箱不正确"
                }
            },
            errorElement: "em"
        });
    });
</script>
